<template>
	<view>
		<view v-if="list==''" style=" width: 100%; font-size: 14px; color: #a3a3a3;text-align: center;">--暂无数据--</view>
		<view v-else>
			<view class="listbox" v-for="(item,index) in list" :key="index" >
				<view class="item" @click="gotovert(item)">
					<view class="listtop">
						<view class="listinfo">
							<view class="name">{{item.realname}}</view>
							<view class="">{{item.mobile}}</view>
						</view>
					</view>
					<view class="listinfo">
						{{item.province}}{{item.city}}{{item.district}}{{item.address}}
					</view>
					<view class="listbutt">
						<view v-if="item.status==1" class="mor">默认</view>
						<!-- <view class="">{{item.address}}</view> -->
					</view>
				</view>
				<view class="icon">
					<up-icon name="trash" size="20px" @click="delress(item)"></up-icon>
					<up-icon name="edit-pen" size="20px" @click="gotocit(item)"></up-icon>
				</view>
			</view>
		</view>
		<view class="buttbox1" @click="gotocity">添加地址</view>
	</view>
</template>

<script setup>
import { ref,onMounted } from 'vue';
import {onShow} from '@dcloudio/uni-app'
import request from '../../utils/request';
let token = ref()
onShow(()=>{
	console.log(111);
	token.value=uni.getStorageSync('token')
	request.post('Transport/index',{header:{
		"token":token.value
	}}).then(res=>{
		console.log(res);
		list.value=res.data
		console.log(list.value);
	}).catch(err=>{
		console.log(err);
	})
})
	let list=ref([
		
	])
	const gotocity=()=>{
		uni.navigateTo({
			url:'/pages/city/city'
		})
	}
	const gotovert=(item)=>{
		uni.$emit('customEvent', {id:item.id});
		uni.navigateBack()
	}
	const gotocit=(item)=>{
		const id=item.id
		console.log(id);
		uni.navigateTo({
			url:`/pages/city/city?id=${id}`
		})
	}
	
	const delress = (item) => {
		request.post('Transport/delete', {
			data: {
				id: item.id
			},
			header: {
				"token": token.value
			}
		}).then(res => {
			console.log(res);
			uni.$u.toast(res.msg)
			request.post('Transport/index',{header:{
				"token":token.value
			}}).then(res=>{
				console.log(res);
				list.value=res.data
				console.log(list.value);
			}).catch(err=>{
				console.log(err);
			})
		}).catch(err => {
			console.log(err);
		})
	}
</script>

<style scoped lang="scss">

	.listbox{
		width: 100%;
		height: 160rpx;
		padding: 0 20rpx;
		padding-top: 30rpx;
		box-sizing: border-box;
		border-bottom: 1px solid #f0f0f0;
		display: flex;
		align-items: center;
		justify-content: space-between;
		
		.icon {
			display: flex;
			flex-direction: column;
		}
	}
	.listtop{
		display: flex;
		align-items: center;
		font-size: 14px;
		justify-content: space-between;
	}
	.listinfo{
		display: flex;
		align-items: center;
		
	}
	.name{
		margin-right: 30rpx;
	}
	.mor{
		width: 80rpx;
		height: 40rpx;
		border-radius: 20rpx;
		line-height: 40rpx;
		text-align: center;
		background-color: #10c696;
		color: #fff;
		margin-right: 30rpx;
		font-size: 12px;
	}
	.listbutt{
		display: flex;
		align-items: center;
		margin-top: 20rpx;
		font-size: 14px;
		color: #989898;
	}
	.buttbox1{
		width: 690rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		color: #fff;
		background-color: #10c696;
		border-radius: 40rpx;
		position: fixed;
		bottom: 30rpx;
		left: 30rpx;
	}
</style>
